home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume89 / graphics / mandelv2.1 < prev    next >
Internet Message Format  |  1989-06-21  |  44KB

  1. Path: xanth!ames!apple!oliveb!sun!swap!page
  2. From: page%swap@Sun.COM (Bob Page)
  3. Newsgroups: comp.sources.amiga
  4. Subject: v89i152:  mandelvroom - mandelbrot explorer v2.0, Part01/09
  5. Message-ID: <111386@sun.Eng.Sun.COM>
  6. Date: 21 Jun 89 04:00:12 GMT
  7. Sender: news@sun.Eng.Sun.COM
  8. Lines: 1826
  9. Approved: page@sun.com
  10.  
  11. Submitted-by: kevin@uts.amdahl.com (Kevin Clague)
  12. Posting-number: Volume 89, Issue 152
  13. Archive-name: graphics/mandelv20.1
  14.  
  15. [The latest and greatest version of Mandelvroom.  If you liked the old
  16. version, you'll be crazy about this one.  Docs and projects are in the
  17. binaries group.  ..bob]
  18.  
  19. # This is a shell archive.
  20. # Remove anything above and including the cut line.
  21. # Then run the rest of the file through 'sh'.
  22. # Unpacked files will be owned by you and have default permissions.
  23. #----cut here-----cut here-----cut here-----cut here----#
  24. #!/bin/sh
  25. # shar: SHell ARchive
  26. # Run the following text through 'sh' to create:
  27. #    cmd.c
  28. #    contour.c
  29. # This is archive 1 of a 9-part kit.
  30. # This archive created: Tue Jun 20 20:45:26 1989
  31. echo "extracting cmd.c"
  32. sed 's/^X//' << \SHAR_EOF > cmd.c
  33. X/*
  34. X * MandelVroom 2.0
  35. X *
  36. X * (c) Copyright 1987,1989  Kevin L. Clague, San Jose, CA
  37. X *
  38. X * All rights reserved.
  39. X *
  40. X * Permission is hereby granted to distribute this program's source
  41. X * executable, and documentation for non-comercial purposes, so long as the
  42. X * copyright notices are not removed from the sources, executable or
  43. X * documentation.  This program may not be distributed for a profit without
  44. X * the express written consent of the author Kevin L. Clague.
  45. X *
  46. X * This program is not in the public domain.
  47. X *
  48. X * Fred Fish is expressly granted permission to distribute this program's
  49. X * source and executable as part of the "Fred Fish freely redistributable
  50. X * Amiga software library."
  51. X *
  52. X * Permission is expressly granted for this program and it's source to be
  53. X * distributed as part of the Amicus Amiga software disks, and the
  54. X * First Amiga User Group's Hot Mix disks.
  55. X *
  56. X * contents: this file contains the IntuiMessage handler (also referred to
  57. X * as the command handler.)  This code implements a command-state state
  58. X * machine.
  59. X */
  60. X
  61. X#include "mandp.h"
  62. X
  63. Xextern struct Picture *ZoomedPict;
  64. X
  65. XBYTE State;
  66. XBYTE Parse_rc;
  67. X
  68. XProcessCmd(Msg)
  69. X  struct IntuiMessage *Msg;
  70. X{
  71. X  DecodeClass(Msg);         /* decode input by class */
  72. X  PostProcessMsg(Msg);      /* set current pen, contour, or range */
  73. X  DisplayMsg();             /* Display a message in the title bar */
  74. X
  75. X  if (State == IDLESTATE) {
  76. X    SetNormPointer();
  77. X  }
  78. X}
  79. X
  80. X/*
  81. X * This function serves the following purposes:
  82. X *    1. Reacts to menu items and command gadgets (overriding whatever
  83. X *       the outstanding state is.)
  84. X *    2. Filters of messages that do not affect the state of
  85. X *       user interaction (NEWSIZE, REFRESHWINDOW, CLOSEWINDOW...)
  86. X *    3. It only allows MOUSEBUTTON messages to get past this
  87. X *       routine if they are desired.
  88. X */
  89. X
  90. XDecodeClass(Msg)
  91. X  struct IntuiMessage *Msg;
  92. X{
  93. X  register struct Window  *Window = Msg->IDCMPWindow;
  94. X  struct Picture *Pict;
  95. X
  96. X  switch( Msg->Class ) {
  97. X
  98. X         /* These Classes can cause State to be set */
  99. X
  100. X    case MENUPICK:
  101. X         HandleMenuPick( Msg );
  102. X         break;
  103. X
  104. X    case GADGETDOWN:
  105. X         HandleGadgetCmd(Msg);
  106. X         break;
  107. X
  108. X    case MOUSEBUTTONS:
  109. X         /* filter unwanted SELECTDOWNS and SELECTUPS */
  110. X         /* So that each of cmd routines below don't  */
  111. X         /* have to ignore them                       */
  112. X
  113. X         if (Msg->IDCMPWindow == ContWind) {
  114. X
  115. X           SlideBarCmd(Msg);
  116. X         } else {
  117. X
  118. X           Pict = (struct Picture *) Window->UserData;
  119. X
  120. X           if (Pict != NULL) {
  121. X
  122. X             /* ignore Project buttons outside the picture area */
  123. X
  124. X             if (Msg->Code == SELECTUP || Msg->Code == SELECTDOWN  &&
  125. X                 MouseX >= Pict->LeftMarg &&
  126. X                 MouseY >= Pict->TopMarg  &&
  127. X                 MouseX <  Window->Width  - Pict->RightMarg &&
  128. X                 MouseY <  Window->Height - Pict->BotMarg ) {
  129. X
  130. X               DecodeState(Msg);
  131. X             }
  132. X           }
  133. X         }
  134. X         break;
  135. X
  136. X         /* this message class cancels any command (i.e. clear state ) */
  137. X
  138. X    case CLOSEWINDOW:
  139. X         CloseWinds( Window );
  140. X         State = IDLESTATE;
  141. X         break;
  142. X
  143. X         /* The response to these message classes depends on what we're
  144. X          * doing.
  145. X          */
  146. X
  147. X    case MOUSEMOVE:
  148. X         DecodeState(Msg);
  149. X         break;
  150. X
  151. X    case GADGETUP:
  152. X         HandleGadgetCmd(Msg);
  153. X      /* DecodeState(Msg); */
  154. X         break;
  155. X
  156. X         /* these message classes do not modify state */
  157. X
  158. X    case ACTIVEWINDOW:
  159. X         ActivatePict( Window );
  160. X         break;
  161. X
  162. X    case NEWSIZE:
  163. X         if (Window != BackWind) {
  164. X           BorderWindow( Window );
  165. X
  166. X           if (Window->UserData) {
  167. X             ScrollPictCmd(Msg);
  168. X           }
  169. X         }
  170. X         break;
  171. X
  172. X    default:
  173. X         printf("Unexpected msg class %04x\n",Msg->Class);
  174. X         break;
  175. X  }
  176. X}
  177. X
  178. XDisplayMsg()
  179. X{
  180. X  char *c;
  181. X  c = NULL;
  182. X
  183. X  switch(State) {
  184. X  case COPYRIGHTSTATE:  c = "Copyright 1987,1989 Kevin Clague";        break;
  185. X  case IDLESTATE:       c = "MandelVroom V2.0 by Kevin Clague";        break;
  186. X  case SETCONTSTATE:    c = "You can set color or height";             break;
  187. X  case ORBITSTATE:      c = "Press left mouse button in Project";      break;
  188. X  case SETJULIASTATE:   c = "Press left mouse button in Mand Project"; break;
  189. X  case ZOOMINSTATE:     c = "Place the Zoom box in a Project";         break;
  190. X  case COPYRGBSTATE:    c = "Select a color pen to copy RGBs";         break;
  191. X  case SPREADRGBSTATE:  c = "Select a color pen to spread RGBs";       break;
  192. X  case XCHGRGBSTATE:    c = "Select a color pen to exchange RGBs";     break;
  193. X  case CYCLERANGESTATE: c = "Select a color pen to complete range";    break;
  194. X  case SMOOTHCONTSTATE: c = "Select a contour pen to smooth heights";  break;
  195. X  case CUTCONTSTATE:    c = "Select a contour pen to cut a pattern";   break;
  196. X  case COPYCONTSTATE:   c = "Select a contour pen to copy a pattern";  break;
  197. X  case PASTECONTSTATE:  c = "Select a contour pen to paste a pattern"; break;
  198. X  case HELPSTATE:       c = "Select a menu or gadget for help";        break;
  199. X  case SCROLLPICTSTATE: c = "Use the mouse to pan the current project";break;
  200. X  case SETHEIGHTSTATE:  c = "Mouse changes contour's lower bound";     break;
  201. X  case SLIDERGBSTATE:   c = "Move the mouse to change RGB values";     break;
  202. X  case SLIDEBARSTATE:   c = "Move the mouse to scroll contours";       break;
  203. X  case RESIZEZOOMSTATE: c = "Move the mouse to size the Zoom box";     break;
  204. X  case ZOOMDRAGSTATE:   c = "Move the mouse to drag the Zoom box";     break;
  205. X  case PROPRESIZESTATE: c = "Move the mouse to size the Zoom box";     break;
  206. X  case SCROLLHELPSTATE: c = "Move the mouse to scroll help info.";     break;
  207. X  case SLIDESPEEDSTATE: c = "Move the mouse to change speed";          break;
  208. X  }
  209. X
  210. X  /* only display the message if it is a new one */
  211. X
  212. X  if (c && screen->Title != c) {
  213. X    SetWindowTitles( CurWind, (char *) -1, c );
  214. X  }
  215. X}
  216. X
  217. XDecodeState(Msg)
  218. X  struct IntuiMessage *Msg;
  219. X{
  220. X  switch(State) {
  221. X    case COPYRIGHTSTATE:
  222. X    case IDLESTATE:        DecodeMsg(Msg);      break;
  223. X    case COPYRGBSTATE:     CopyRGBCmd(Msg);     break;
  224. X    case SPREADRGBSTATE:   SpreadRGBCmd(Msg);   break;
  225. X    case XCHGRGBSTATE:     ExchangeRGBCmd(Msg); break;
  226. X    case SLIDERGBSTATE:    SlideRGBCmd(Msg);    break;
  227. X    case SETHEIGHTSTATE:   SetHeightCmd(Msg);   break;
  228. X    case SETCONTSTATE:     SetContCmd(Msg);     break;
  229. X    case SMOOTHCONTSTATE:  SmoothContCmd(Msg);  break;
  230. X    case CUTCONTSTATE:     CutContCmd(Msg);     break;
  231. X    case COPYCONTSTATE:    CopyContCmd(Msg);    break;
  232. X    case PASTECONTSTATE:   PasteContCmd(Msg);   break;
  233. X    case SLIDEBARSTATE:    SlideBarCmd(Msg);    break;
  234. X    case ORBITSTATE:       OrbitCmd(Msg);       break;
  235. X    case ZOOMINSTATE:      ZoomInCmd(Msg);      break;
  236. X    case RESIZEZOOMSTATE:  ResizeZoomCmd(Msg);  break;
  237. X    case QUERYHEIGHTSTATE: QueryHeightCmd(Msg); break;
  238. X    case ZOOMDRAGSTATE:    ZoomDragCmd(Msg);    break;
  239. X    case PROPRESIZESTATE:  PropResizeCmd(Msg);  break;
  240. X    case SETJULIASTATE:    SetJuliaCmd(Msg);    break;
  241. X    case SLIDESPEEDSTATE:  SlideSpeedCmd(Msg);  break;
  242. X    case CYCLERANGESTATE:  CycleRangeCmd(Msg);  break;
  243. X    case SCROLLHELPSTATE:  ScrollHelpCmd(Msg);  break;
  244. X    case SCROLLPICTSTATE:  ScrollPictCmd(Msg);  break;
  245. X  }
  246. X}
  247. X
  248. X/*
  249. X * Set Current pen or current contour.
  250. X */
  251. X
  252. XPostProcessMsg(Msg)
  253. X  struct IntuiMessage *Msg;
  254. X{
  255. X  register struct Window  *Window = Msg->IDCMPWindow;
  256. X  struct Gadget *gadget;
  257. X  int    id;
  258. X
  259. X  if (Msg->Class == GADGETDOWN) {
  260. X
  261. X    gadget = (struct Gadget *) Msg->IAddress;
  262. X    id = gadget->GadgetID;
  263. X    switch (WIND_TYPE(id)) {
  264. X
  265. X      case PALTYPE:
  266. X           if (GADG_TYPE(id) == PALPENS) {
  267. X             SetCurPen(GADG_NUM(id));
  268. X           }
  269. X           break;
  270. X
  271. X      case CONTYPE:
  272. X           if ((GADG_TYPE(id) == CONTSELS || GADG_TYPE(id) == CONTPOTS) &&
  273. X             id != CONTLAST) {
  274. X
  275. X             SelContCmd(Msg);
  276. X           }
  277. X    }
  278. X  }
  279. X}
  280. X
  281. X/*
  282. X * This is mostly for MOUSEBUTTON related commands (where the MOUSEBUTTONS
  283. X * are commands like drag, close or resize zoom box.)
  284. X */
  285. X
  286. XDecodeMsg(Msg)
  287. X  struct IntuiMessage *Msg;
  288. X{
  289. X  switch( Msg->Class ) {
  290. X
  291. X    case MOUSEBUTTONS:
  292. X         /* query height */
  293. X         DecodePictMouseButtons( Msg );
  294. X         break;
  295. X  }
  296. X}
  297. X
  298. XHandleGadgetCmd(Msg)
  299. X  struct IntuiMessage *Msg;
  300. X{
  301. X  struct Gadget *gadget;
  302. X  int id, type, num;
  303. X
  304. X  if (State == HELPSTATE) {
  305. X    HelpGadgetCmd(Msg);
  306. X    State = IDLESTATE;
  307. X    return;
  308. X  }
  309. X
  310. X  gadget = (struct Gadget *) Msg->IAddress;
  311. X
  312. X  id   = gadget->GadgetID;
  313. X  type = GADG_TYPE(id);
  314. X
  315. X  switch( WIND_TYPE(id)) {
  316. X
  317. X    case PICTTYPE:
  318. X         State = IDLESTATE;
  319. X         switch (id) {
  320. X           case PICTGEN:   GenerateCmd(Msg); break;
  321. X           case PICTIN:    ZoomInCmd(Msg);   break;
  322. X           case PICTOUT:   ZoomOutCmd(Msg);  break;
  323. X           case PICTJULIA: SetJuliaCmd(Msg); break;
  324. X         }
  325. X         MakeCurProj((struct Picture *) Msg->IDCMPWindow->UserData);
  326. X         break;
  327. X
  328. X    case PALTYPE:
  329. X         StopCycle();
  330. X         switch (type) {
  331. X           case PALPENS:          DecodeState(Msg);    break;
  332. X           case PALPOTS:          SlideRGBCmd(Msg);    break;
  333. X           case PALCNTLS:
  334. X                switch (id) {
  335. X                  case PALCOPY:   CopyRGBCmd(Msg);     break;
  336. X                  case PALRANGE:  SpreadRGBCmd(Msg);   break;
  337. X                  case PALEXCG:   ExchangeRGBCmd(Msg); break;
  338. X                }
  339. X                break;
  340. X         }
  341. X         break;
  342. X
  343. X    case CYCTYPE:
  344. X         switch (type) {
  345. X           case CYCRNUMS:         SelRangeCmd(Msg);   break;
  346. X           case CYCCNTLS:
  347. X                switch (id) {
  348. X                  case CYCSPEED:  SlideSpeedCmd(Msg); break;
  349. X                  case CYCRANGE:  CycleRangeCmd(Msg); break;
  350. X                  case CYCDIR:    ToggleDirCmd(Msg);  break;
  351. X                  case CYCON:     CycleOnOffCmd(Msg); break;
  352. X                }
  353. X                break;
  354. X
  355. X         }
  356. X         break;
  357. X
  358. X    case CONTYPE:
  359. X         StopCycle();
  360. X         switch (type) {
  361. X           case CONTSELS:         DecodeState(Msg);   break;
  362. X           case CONTPOTS:         SetHeightCmd(Msg);  break;
  363. X           case CONTCNTLS:
  364. X                switch (id) {
  365. X                  case CONTRECOL: PaintCmd(Msg);      break;
  366. X                  case CONTSET:   SetContCmd(Msg);    break;
  367. X                  case CONTSMTH:  SmoothContCmd(Msg); break;
  368. X                  case CONTCUT:   CutContCmd(Msg);    break;
  369. X                  case CONTCOPY:  CopyContCmd(Msg);   break;
  370. X                  case CONTPASTE: PasteContCmd(Msg);  break;
  371. X                  case CONTCEIL:  CeilingCmd(Msg);    break;
  372. X                }
  373. X                break;
  374. X         }
  375. X         break;
  376. X
  377. X    case ORBTTYPE:
  378. X         OrbitCmd(Msg);
  379. X         break;
  380. X
  381. X    case HELPTYPE:
  382. X         switch (id) {
  383. X
  384. X           case HELPUP:
  385. X           case HELPDOWN:
  386. X                Page_File(id);
  387. X                break;
  388. X
  389. X           case HELPSCROLL:
  390. X                ScrollHelpCmd(Msg);
  391. X                break;
  392. X         }
  393. X  }
  394. X}
  395. X
  396. XDecodePictMouseButtons( Msg )
  397. X  struct IntuiMessage *Msg;
  398. X{
  399. X  register struct Node    *zNode;
  400. X  register struct Picture *ZoomPict;
  401. X  register struct Picture *Pict;
  402. X           struct Picture *PictAddr();
  403. X  int rc;
  404. X
  405. X  Pict = (struct Picture *) Msg->IDCMPWindow->UserData;
  406. X
  407. X  zNode = Pict->zList.lh_Head;
  408. X
  409. X  rc = NOTHINGHIT;
  410. X
  411. X  while ( rc == NOTHINGHIT && zNode->ln_Succ ) {
  412. X
  413. X    ZoomPict = PictAddr( zNode );
  414. X
  415. X    switch( rc = CheckPictZoomBox( ZoomPict ) ) {
  416. X
  417. X      case ZOOMCLOSEHIT: /* User closed the zoom box */
  418. X           ClearZoomBox( ZoomPict );
  419. X           break;
  420. X
  421. X      case ZOOMDRAGHIT:
  422. X           ZoomedPict = ZoomPict;
  423. X           ZoomDragCmd(Msg);
  424. X           break;
  425. X
  426. X      case ZOOMRESIZEHIT:
  427. X           ZoomedPict = ZoomPict;
  428. X           ResizeZoomCmd(Msg);
  429. X           break;
  430. X
  431. X      case PROPRESIZEHIT:
  432. X           ZoomedPict = ZoomPict;
  433. X           PropResizeCmd(Msg);
  434. X           break;
  435. X    }
  436. X
  437. X    zNode = zNode->ln_Succ;
  438. X  }
  439. X
  440. X  if (rc == NOTHINGHIT) {
  441. X    QueryHeightCmd(Msg);
  442. X  }
  443. X}
  444. SHAR_EOF
  445. echo "extracting contour.c"
  446. sed 's/^X//' << \SHAR_EOF > contour.c
  447. X/*
  448. X * MandelVroom 2.0
  449. X *
  450. X * (c) Copyright 1987,1989  Kevin L. Clague, San Jose, CA
  451. X *
  452. X * All rights reserved.
  453. X *
  454. X * Permission is hereby granted to distribute this program's source
  455. X * executable, and documentation for non-comercial purposes, so long as the
  456. X * copyright notices are not removed from the sources, executable or
  457. X * documentation.  This program may not be distributed for a profit without
  458. X * the express written consent of the author Kevin L. Clague.
  459. X *
  460. X * This program is not in the public domain.
  461. X *
  462. X * Fred Fish is expressly granted permission to distribute this program's
  463. X * source and executable as part of the "Fred Fish freely redistributable
  464. X * Amiga software library."
  465. X *
  466. X * Permission is expressly granted for this program and it's source to be
  467. X * distributed as part of the Amicus Amiga software disks, and the
  468. X * First Amiga User Group's Hot Mix disks.
  469. X *
  470. X * contents: this file contains the code to open and close the contour
  471. X * palette tool.  It also contains the code that implements the contour
  472. X * commands.
  473. X */
  474. X
  475. X#include "mandp.h"
  476. X
  477. XUBYTE ContOpen;
  478. X
  479. Xstruct Window *ContWind;
  480. X
  481. XBYTE ContTitle[80];
  482. X
  483. Xstruct NewWindow NewCont = {
  484. X   0,200-80,                 /* start position           */
  485. X   320,200,                  /* width, height            */
  486. X   (UBYTE) 0, (UBYTE) -1,   /* detail pen, block pen    */
  487. X   NULL,                     /* IDCMP flags */
  488. X                             /* MandWind flags */
  489. X   WINDOWCLOSE | WINDOWDRAG | WINDOWDEPTH | NOCAREREFRESH | SMART_REFRESH |
  490. X   REPORTMOUSE,
  491. X   (struct Gadget *) NULL,   /* first gadget             */
  492. X   (struct Image *) NULL,    /* user checkmark           */
  493. X   (UBYTE *) NULL,           /* window title             */
  494. X   (struct Screen *) NULL,   /* pointer to screen        */
  495. X   (struct BitMap *) NULL,   /* pointer to superbitmap   */
  496. X   80,80,320,200,            /* sizing                   */
  497. X   CUSTOMSCREEN              /* type of screen           */
  498. X   };
  499. X
  500. X
  501. XSHORT Ceiling = 1023;
  502. X
  503. XSHORT  NumContours = NUMCONTS;
  504. XSHORT  FirstContour = 0;
  505. XSHORT  SaveFirstCont = 0;
  506. X
  507. Xint    CurContour;
  508. X
  509. Xstruct Gadget *ContGadget[DISPCONTS];
  510. Xstruct Gadget *SelGadget[DISPCONTS];
  511. X
  512. XUBYTE  Pattern[NUMCONTS+4];
  513. XSHORT  PattSize;
  514. X
  515. Xstatic struct Gadget *ModGadget;
  516. X
  517. Xint    BarHotSpot;
  518. X
  519. XLONG BarTop;
  520. XLONG BarBot;
  521. XLONG BarLeft;
  522. XLONG BarRight;
  523. XLONG BarWidth;
  524. XLONG BarBoxTop;
  525. XLONG BarBoxBot;
  526. X
  527. Xint ScaledFirst;
  528. X
  529. Xstruct ContHoriz {
  530. X  int CmdLeft;
  531. X  int BarLeft;
  532. X  int BarWidth;
  533. X  int PenLeft;
  534. X  int PenWidth;
  535. X};
  536. X
  537. Xstruct ContVert {
  538. X  int CmdTop;
  539. X  int BarTop;
  540. X  int BarHeight;
  541. X  int PenTop;
  542. X  int PenHeight;
  543. X};
  544. X
  545. Xstatic struct ContHoriz  Horiz_I     = {  3,   8,  262,   8, 6*33 };
  546. Xstatic struct ContHoriz  Horiz_II    = {  3,   8,  524,   8,12*32 + 4};
  547. Xstatic struct ContVert   Verticle_I  = { 11,   31,  10,  47, 42   };
  548. Xstatic struct ContVert   Verticle_II = { 11,   31,  14,  52, 82  };
  549. X
  550. Xstatic struct ContHoriz *CurH = &Horiz_I;
  551. Xstatic struct ContVert  *CurV = &Verticle_I;
  552. X
  553. X
  554. X/*
  555. X * Contour related commands
  556. X */
  557. X
  558. X/* Paint Command */
  559. X
  560. XPaintCmd(Msg)
  561. X  struct IntuiMessage *Msg;
  562. X{
  563. X  ReColor( CurPict );
  564. X  DisplayBeep(screen);
  565. X
  566. X  if ( CurPict->DrawPict ) {
  567. X    ZoomBox( CurPict );
  568. X  }
  569. X}
  570. X
  571. XSelContCmd(Msg)
  572. X  struct IntuiMessage *Msg;
  573. X{
  574. X  struct Gadget *gadget;
  575. X
  576. X  gadget = (struct Gadget *) Msg->IAddress;
  577. X
  578. X  SetCurCont(GADG_NUM(gadget->GadgetID));
  579. X}
  580. X
  581. XSetHeightCmd(Msg)
  582. X  struct IntuiMessage *Msg;
  583. X{
  584. X  struct Window *Window;
  585. X  static struct Gadget *gadget;
  586. X  struct PropInfo *propinfo;
  587. X  static int knobhit;
  588. X
  589. X  Window = Msg->IDCMPWindow;
  590. X
  591. X  switch( Msg->Class ) {
  592. X
  593. X    case GADGETDOWN:
  594. X         gadget = (struct Gadget *) Msg->IAddress;
  595. X         propinfo = (struct PropInfo *) gadget->SpecialInfo;
  596. X
  597. X         if (knobhit = propinfo->Flags & KNOBHIT) {
  598. X           ModifyIDCMP(Window, Window->IDCMPFlags | MOUSEMOVE);
  599. X           State  = SETHEIGHTSTATE;
  600. X         } else {
  601. X           SetContourHeight(gadget);
  602. X         }
  603. X         break;
  604. X
  605. X    case MOUSEMOVE:
  606. X         SetContourHeight(gadget);                         /* potentio */
  607. X         break;
  608. X
  609. X    case GADGETUP:
  610. X         if (knobhit) {
  611. X           ModifyIDCMP(Window, Window->IDCMPFlags & ~MOUSEMOVE);
  612. X           ModAll();
  613. X         } else {
  614. X           SetContourHeight(gadget);                         /* potentio */
  615. X           ShowValid();
  616. X         }
  617. X         State = IDLESTATE;
  618. X         break;
  619. X  }
  620. X}
  621. X
  622. XSetContCmd(Msg)  /* user can set height or pen */
  623. X  struct IntuiMessage *Msg;
  624. X{
  625. X  struct Window  *Window;
  626. X  struct Gadget  *gadget;
  627. X  struct Picture *Pict;
  628. X
  629. X  Window = Msg->IDCMPWindow;
  630. X  gadget = (struct Gadget *) Msg->IAddress;
  631. X
  632. X  switch( Msg->Class ) {
  633. X
  634. X    case GADGETDOWN:
  635. X         switch( WIND_TYPE(gadget->GadgetID) ) {
  636. X
  637. X           case CONTYPE:
  638. X                if (gadget->GadgetID == CONTSET) {
  639. X
  640. X                  SetToPointer();
  641. X                  State = SETCONTSTATE;
  642. X                }
  643. X                break;
  644. X
  645. X           case PALTYPE:
  646. X                if (GADG_TYPE(gadget->GadgetID) == PALPENS) {
  647. X
  648. X                  State = IDLESTATE;
  649. X                  SetContourPen( GADG_NUM(gadget->GadgetID) );
  650. X                }
  651. X                break;
  652. X         }
  653. X         break;
  654. X
  655. X    case MOUSEBUTTONS:             /* selecting height from the picture */
  656. X
  657. X         if (Msg->Code == SELECTDOWN) {
  658. X           Pict = (struct Picture *) Window->UserData;
  659. X           if ( Pict ) {
  660. X             State = IDLESTATE;
  661. X             DoWindowPick(Pict,MouseX,MouseY);
  662. X           }
  663. X         }
  664. X         break;
  665. X  }
  666. X}
  667. X
  668. XSmoothContCmd(Msg)  /* Smooth heights between two pens */
  669. X  struct IntuiMessage *Msg;
  670. X{
  671. X  struct Gadget  *gadget;
  672. X  int    t;
  673. X
  674. X  /* Need contour selection to complete */
  675. X
  676. X  gadget = (struct Gadget *) Msg->IAddress;
  677. X
  678. X  if (Msg->Class == GADGETDOWN) {
  679. X
  680. X    if (gadget->GadgetID == CONTSMTH) { /* Smooth command gadget */
  681. X
  682. X      SetToPointer();
  683. X      State = SMOOTHCONTSTATE;
  684. X    } else {
  685. X
  686. X      t = GADG_TYPE(gadget->GadgetID);
  687. X
  688. X      if (t == CONTSELS || t == CONTPOTS) {
  689. X
  690. X        t = GADG_NUM(gadget->GadgetID);
  691. X
  692. X        /* smooth to last does decrement by one */
  693. X
  694. X        if (t == CONTLAST)
  695. X          *(CurPict->Heights + t) = 0x7fff;
  696. X
  697. X        SmoothContours(CurContour, t);
  698. X        State = IDLESTATE;
  699. X      }
  700. X    }
  701. X  }
  702. X}
  703. X
  704. XCutContCmd(Msg)  /* Cut Pens between two contours */
  705. X  struct IntuiMessage *Msg;
  706. X{
  707. X  struct Gadget  *gadget;
  708. X  int    t;
  709. X
  710. X  /* Need contour selection to complete */
  711. X
  712. X  gadget = (struct Gadget *) Msg->IAddress;
  713. X
  714. X  if (Msg->Class == GADGETDOWN) {
  715. X
  716. X    if (gadget->GadgetID == CONTCUT) { /* Cut command gadget */
  717. X
  718. X      SetToPointer();
  719. X      State = CUTCONTSTATE;
  720. X    } else {
  721. X
  722. X      t = GADG_TYPE(gadget->GadgetID);
  723. X
  724. X      if (t == CONTSELS || t == CONTPOTS) {
  725. X
  726. X        t = GADG_NUM(gadget->GadgetID);
  727. X
  728. X        CopyPattern(   CurContour, t);
  729. X        DeleteContours(CurContour, t);
  730. X        State = IDLESTATE;
  731. X      }
  732. X    }
  733. X  }
  734. X}
  735. X
  736. XCopyContCmd(Msg)  /* Copy Pens between two contours */
  737. X  struct IntuiMessage *Msg;
  738. X{
  739. X  struct Gadget  *gadget;
  740. X  int    t;
  741. X
  742. X  /* Need contour selection to complete */
  743. X
  744. X  gadget = (struct Gadget *) Msg->IAddress;
  745. X
  746. X  if (Msg->Class == GADGETDOWN)  {
  747. X    if (WIND_TYPE(gadget->GadgetID) == CONTYPE) {
  748. X
  749. X      if (gadget->GadgetID == CONTCOPY) { /* Copy command gadget */
  750. X
  751. X        SetToPointer();
  752. X        State = COPYCONTSTATE;
  753. X      } else {
  754. X
  755. X        t = GADG_TYPE(gadget->GadgetID);
  756. X
  757. X        if (t == CONTSELS || t == CONTPOTS) {
  758. X
  759. X          CopyPattern( CurContour, GADG_NUM(gadget->GadgetID));
  760. X          State = IDLESTATE;
  761. X        }
  762. X      }
  763. X    } else
  764. X    if (WIND_TYPE(gadget->GadgetID) == PALTYPE) {
  765. X      SetPenPattern(CurPen, GADG_NUM(gadget->GadgetID));
  766. X      State = IDLESTATE;
  767. X    }
  768. X  }
  769. X}
  770. X
  771. XPasteContCmd(Msg)  /* Paste pens into contours */
  772. X  struct IntuiMessage *Msg;
  773. X{
  774. X  struct Gadget  *gadget;
  775. X  int    t;
  776. X
  777. X  /* Need contour selection to complete */
  778. X
  779. X  gadget = (struct Gadget *) Msg->IAddress;
  780. X
  781. X  if (Msg->Class == GADGETDOWN) {
  782. X
  783. X    if (gadget->GadgetID == CONTPASTE) { /* Paste command gadget */
  784. X
  785. X      SetToPointer();
  786. X      State = PASTECONTSTATE;
  787. X    } else {
  788. X
  789. X      t = GADG_TYPE(gadget->GadgetID);
  790. X
  791. X      if (t == CONTSELS || t == CONTPOTS) {
  792. X
  793. X        PastePattern( CurContour, GADG_NUM(gadget->GadgetID));
  794. X        State = IDLESTATE;
  795. X      }
  796. X    }
  797. X  }
  798. X}
  799. X
  800. XCeilingCmd(Msg)  /* Respond to ceiling gadget */
  801. X  struct IntuiMessage *Msg;
  802. X{
  803. X  struct Gadget  *gadget;
  804. X  struct PropInfo *PropInfo;
  805. X  ULONG  VertPot;
  806. X
  807. X  extern SHORT    Ceiling;
  808. X
  809. X  if ( Msg->Class == GADGETUP ) {
  810. X
  811. X    /* Need gadget up to complete */
  812. X
  813. X    gadget = (struct Gadget *) Msg->IAddress;
  814. X    PropInfo = (struct PropInfo *) gadget->SpecialInfo;
  815. X
  816. X    VertPot  = PropInfo->VertPot;
  817. X    VertPot ^= 0xffff;
  818. X    VertPot += 1;
  819. X    Ceiling = VertPot * CurPict->MaxIteration >> 16;
  820. X
  821. X    ModAll();
  822. X    State = IDLESTATE;
  823. X  }
  824. X}
  825. X
  826. XSlideBarCmd(Msg)
  827. X  struct IntuiMessage *Msg;
  828. X{
  829. X  struct Window *Window;
  830. X  static SavedState;
  831. X
  832. X  Window = Msg->IDCMPWindow;                  /* had better be ContWind */
  833. X
  834. X  switch( Msg->Class ) {
  835. X
  836. X    case MOUSEBUTTONS:                        /* slide is starting */
  837. X         switch( Msg->Code ) {
  838. X
  839. X           case SELECTDOWN:                   /* ImmediateCmd() filters */
  840. X                if (InBarBox()) {
  841. X                  StartBarDrag();
  842. X                  ModifyIDCMP(Window, Window->IDCMPFlags | MOUSEMOVE);
  843. X                  SavedState = State;
  844. X                  State = SLIDEBARSTATE;
  845. X                }
  846. X                break;
  847. X
  848. X           case SELECTUP:                     /* slide is stoping */
  849. X                if (State == SLIDEBARSTATE) {
  850. X                  ModAll();
  851. X                  ModifyIDCMP(Window, Window->IDCMPFlags & ~MOUSEMOVE);
  852. X                  State = SavedState;
  853. X                }
  854. X                break;
  855. X         }
  856. X         break;
  857. X
  858. X    case MOUSEMOVE:
  859. X         DragBarBox();                        /* slide the bar */
  860. X         break;
  861. X  }
  862. X}
  863. X
  864. XContNum(num)
  865. X  int num;
  866. X{
  867. X  if (num == 32)
  868. X    return(255);
  869. X  else
  870. X    return(num+FirstContour);
  871. X}
  872. X
  873. XRefreshContours()
  874. X{
  875. X  if ( ContWind ) {
  876. X
  877. X    Ceiling = CurPict->MaxIteration;
  878. X    DrawColorBox( ScaledFirst );
  879. X    DrawColorBar();
  880. X    ReDispPens();
  881. X    ModAll();
  882. X  }
  883. X}
  884. X
  885. XInBarBox()
  886. X{
  887. X  return(MouseX >= BarLeft + ScaledFirst             &&
  888. X         MouseX <= BarLeft + BarWidth  + ScaledFirst &&
  889. X         MouseY >= BarBoxTop                         &&
  890. X         MouseY <= BarBoxBot                             );
  891. X}
  892. X
  893. XStartBarDrag()
  894. X{
  895. X  BarHotSpot = MouseX - BarLeft - ScaledFirst;
  896. X}
  897. X
  898. XDrawColorBar()
  899. X{
  900. X  register LONG x,s,sx;
  901. X  register LONG dx  = XScale + 1;
  902. X
  903. X  register struct RastPort *Rp = ContWind->RPort;
  904. X
  905. X  register UBYTE *ColorPtr = CurPict->Pens;
  906. X
  907. X  sx = BarLeft;
  908. X
  909. X  for (x = 0; x < NumContours; x++ ) {
  910. X
  911. X    SetAPen( Rp, (long) *ColorPtr++ );
  912. X
  913. X    for (s = 0; s < dx; s++) {
  914. X
  915. X      Move(Rp, sx,   BarTop );
  916. X      Draw(Rp, sx++, BarBot );
  917. X    }
  918. X  }
  919. X  DrawColorBox( ScaledFirst );
  920. X}
  921. X
  922. XDrawColorBox( Contour )
  923. X  int Contour;
  924. X{
  925. X  register LONG Left = BarLeft + Contour;
  926. X
  927. X  DrawBox( ContWind, Left, BarBoxTop, Left + BarWidth, BarBoxBot);
  928. X}
  929. X
  930. XDragBarBox()
  931. X{
  932. X  register int CurX;
  933. X  static int OldCurX;
  934. X
  935. X  CurX = MouseX;
  936. X
  937. X  if (CurX == OldCurX)
  938. X    return;
  939. X
  940. X  OldCurX = CurX;
  941. X
  942. X  if ( CurX < BarLeft + BarHotSpot )
  943. X    CurX = BarLeft + BarHotSpot;
  944. X  else
  945. X  if ( CurX > BarRight - BarWidth + BarHotSpot )
  946. X    CurX = BarRight - BarWidth + BarHotSpot;
  947. X
  948. X  DrawColorBox( ScaledFirst );
  949. X  DrawContBox( CurContour, NORMALPEN );
  950. X
  951. X  ScaledFirst = (CurX - BarLeft - BarHotSpot);
  952. X  FirstContour = ScaledFirst >> XScale;
  953. X
  954. X  DrawColorBox( ScaledFirst );
  955. X  DrawContBox( CurContour, HIGHLIGHTPEN );
  956. X
  957. X  ReDispPens();
  958. X}
  959. X
  960. XSetContourPen( Pen )
  961. X  USHORT Pen;
  962. X{
  963. X  register struct Image *Image;
  964. X
  965. X  Image = (struct Image *) SelGadget[ CurContour ]->GadgetRender;
  966. X
  967. X  Image = Image->NextImage;
  968. X  Image->PlaneOnOff = Pen;
  969. X
  970. X  RefreshGList( SelGadget[ CurContour ], ContWind, NULL, 1);
  971. X
  972. X  *(CurPict->Pens + CurContour + FirstContour) = Pen;
  973. X
  974. X  UpdateColorBar( Pen );
  975. X}
  976. X
  977. XUpdateColorBar( Pen )
  978. X  USHORT Pen;
  979. X{
  980. X  register LONG ContourPos;
  981. X  register UBYTE Overlap;
  982. X  register LONG  x, sx;
  983. X
  984. X  register struct RastPort *Rp = ContWind->RPort;
  985. X
  986. X  ContourPos = ((CurContour + FirstContour) << XScale);
  987. X
  988. X  Overlap =
  989. X      ContourPos == ScaledFirst || ContourPos == ScaledFirst + BarWidth;
  990. X
  991. X  if ( Overlap )
  992. X    DrawColorBox( ScaledFirst );
  993. X
  994. X  sx = BarLeft + ((CurContour + FirstContour) << XScale);
  995. X
  996. X  SetAPen( Rp, (long) Pen );
  997. X
  998. X  for (x = 0; x < XScale + 1; x++) {
  999. X
  1000. X    Move(Rp, sx,   BarTop );
  1001. X    Draw(Rp, sx++, BarBot );
  1002. X  }
  1003. X
  1004. X  if ( Overlap )
  1005. X    DrawColorBox( ScaledFirst );
  1006. X}
  1007. X
  1008. XSetCurCont(ContNum)
  1009. X  int ContNum;  /* relative to FirstCont */
  1010. X{
  1011. X  if (ContNum == CONTLAST)
  1012. X    return;
  1013. X
  1014. X  SaveFirstCont = FirstContour;
  1015. X
  1016. X  DrawContBox(CurContour, NORMALPEN );
  1017. X  DrawContBox(ContNum, HIGHLIGHTPEN );
  1018. X
  1019. X  CurContour = ContNum;
  1020. X  SetContTitle(ContNum);
  1021. X}
  1022. X
  1023. XSetContourHeight(gadget)
  1024. X  struct Gadget *gadget;
  1025. X{
  1026. X  struct  PropInfo *PropInfo;
  1027. X  ULONG   VertPot;
  1028. X  SHORT  *Contour;
  1029. X  int     ContNum;
  1030. X
  1031. X  PropInfo = (struct PropInfo *) gadget->SpecialInfo;
  1032. X
  1033. X  VertPot  = PropInfo->VertPot;
  1034. X
  1035. X  VertPot ^= 0xffff;
  1036. X  VertPot += 1;
  1037. X
  1038. X  ContNum = GADG_NUM(gadget->GadgetID);
  1039. X  Contour = CurPict->Heights + FirstContour + ContNum;
  1040. X
  1041. X  if (*Contour <= Ceiling)
  1042. X    *Contour = VertPot * Ceiling >> 16;
  1043. X
  1044. X  SetCurCont(ContNum);
  1045. X}
  1046. X
  1047. X/*
  1048. X * Set the contour window's new title
  1049. X */
  1050. XSetContTitle(ContNum)
  1051. X  int ContNum;
  1052. X{
  1053. X  register SHORT Low, High;
  1054. X  register SHORT *Contour;
  1055. X  register UBYTE *Color;
  1056. X
  1057. X  register char *fmt1 = "C: %-3d  P: %-2d  H: %3d-%d";
  1058. X  register char *fmt2 = "C: %-3d  P: %-2d  H: %3d";
  1059. X
  1060. X  ContNum += FirstContour;
  1061. X
  1062. X  Contour = CurPict->Heights + ContNum;
  1063. X
  1064. X  Color = CurPict->Pens + ContNum;
  1065. X
  1066. X  High = *Contour;
  1067. X
  1068. X  if (ContNum != 0) {
  1069. X    Low  = *(Contour - 1);
  1070. X
  1071. X    if (Low == High || Low - High == 1) {
  1072. X      sprintf(ContTitle, fmt2, ContNum, *Color, High);
  1073. X    } else {
  1074. X      if (Low < High)
  1075. X        sprintf(ContTitle, fmt2, ContNum, *Color, High);
  1076. X      else
  1077. X        sprintf(ContTitle, fmt1, ContNum, *Color, Low - 1, High);
  1078. X    }
  1079. X  } else {
  1080. X
  1081. X    sprintf(ContTitle, fmt2, ContNum, *Color, High);
  1082. X  }
  1083. X  SetWindowTitles(ContWind, ContTitle, NULL);
  1084. X}
  1085. X
  1086. X/*
  1087. X * Set Selection's pen
  1088. X */
  1089. XDrawContBox(Contour, pen)
  1090. X  int  Contour;
  1091. X  LONG pen;
  1092. X{
  1093. X  register LONG Left, Right, Top, Bottom;
  1094. X  register struct RastPort *Rp = ContWind->RPort;
  1095. X
  1096. X  static LONG LastCont;
  1097. X
  1098. X  int Cont;
  1099. X
  1100. X  if ( pen == NORMALPEN ) {
  1101. X
  1102. X    Cont = LastCont;
  1103. X  } else {
  1104. X
  1105. X    LastCont = Cont = Contour + SaveFirstCont - FirstContour;
  1106. X  }
  1107. X
  1108. X  if (Cont >= 0 && Cont < DISPCONTS) {
  1109. X
  1110. X    Left = (6 << XScale) * Cont + CurH->PenLeft - 1;
  1111. X    Right = Left + (4 << XScale) + 2 + XScale;
  1112. X
  1113. X    Top = CurV->PenTop - 1;
  1114. X    Bottom = Top + (4 << YScale) + 2 + YScale;
  1115. X
  1116. X    SetDrMd(Rp, (LONG) JAM1);
  1117. X    SetAPen(Rp, pen);
  1118. X    /*
  1119. X     * Draw the new box
  1120. X     */
  1121. X    Move(Rp, Left,  Top   );
  1122. X    Draw(Rp, Right, Top   );
  1123. X
  1124. X    if (pen == HIGHLIGHTPEN) SetAPen( Rp, SHADOWPEN );
  1125. X
  1126. X    Draw(Rp, Right, Bottom);
  1127. X    Draw(Rp, Left,  Bottom);
  1128. X
  1129. X    SetAPen( Rp, (long) pen );
  1130. X
  1131. X    Draw(Rp, Left,  Top+1 );
  1132. X  }
  1133. X} /* DrawContBox */
  1134. X
  1135. X/*
  1136. X *  There was a window pick. Do what we need to do to service it
  1137. X */
  1138. XDoWindowPick(Pict,MouseX,MouseY)
  1139. X  register struct Picture *Pict;
  1140. X  register SHORT MouseX,MouseY;
  1141. X{
  1142. X  register struct Window *Window = CurPict->Window;
  1143. X  register USHORT Height;
  1144. X
  1145. X  if (Pict->Flags & NO_RAM_GENERATE)
  1146. X    return;
  1147. X
  1148. X  Height = HeightPicked( Pict, MouseX, MouseY );
  1149. X  *(CurPict->Heights + CurContour + FirstContour) = Height;
  1150. X  ModAll();
  1151. X}
  1152. X
  1153. Xint
  1154. XHeightPicked( Pict, MouseX, MouseY )
  1155. X  register struct Picture *Pict;
  1156. X  register SHORT MouseX,MouseY;
  1157. X{
  1158. X  return( *(Pict->Counts + (MouseY - Pict->TopMarg) * Pict->CountX +
  1159. X                            MouseX - Pict->LeftMarg));
  1160. X}
  1161. X
  1162. X/*
  1163. X *  Smooth the heights over a subrange of contours
  1164. X */
  1165. XSmoothContours(First,Second)
  1166. X  int First;
  1167. X  int Second;
  1168. X{
  1169. X  register USHORT Temp;
  1170. X  register SHORT *StartP,*EndP;
  1171. X  register float Diff,Start;
  1172. X
  1173. X  First += SaveFirstCont;
  1174. X  Second = ContNum(Second);
  1175. X
  1176. X  if (Second-First != 0) {
  1177. X
  1178. X    if (Second < First) {
  1179. X      Temp = First;
  1180. X      First = Second;
  1181. X      Second = Temp;
  1182. X    }
  1183. X
  1184. X    StartP = CurPict->Heights + First;
  1185. X    EndP   = CurPict->Heights + Second;
  1186. X
  1187. X    Start =  (float) *StartP;
  1188. X    Diff  = ((float) *EndP - Start) / (float) (Second-First);
  1189. X
  1190. X    if (Diff > -1.0) {
  1191. X      Diff = -1.0;
  1192. X    }
  1193. X
  1194. X    for ( ; First < Second && Start > 0; First++)
  1195. X      *(StartP++ + 1) = (SHORT) (Start += Diff);
  1196. X
  1197. X    if (Start == 0) {
  1198. X      for ( ; First < NumContours; First++) {
  1199. X        *StartP++ = 0;
  1200. X      }
  1201. X    }
  1202. X
  1203. X    ModAll();
  1204. X  }
  1205. X} /* SmoothContours */
  1206. X
  1207. X/*
  1208. X *  Copy the pattern from the palette into pattern area
  1209. X */
  1210. XCopyPattern(First,Second)
  1211. X  int First, Second;
  1212. X{
  1213. X  register int i, spacing;
  1214. X  register UBYTE *ColorPatt = CurPict->Pens;
  1215. X  register struct StringInfo *String =
  1216. X                  (struct StringInfo *) ModGadget->SpecialInfo;
  1217. X
  1218. X  LONG Spacing;
  1219. X
  1220. X  UBYTE *Last = ColorPatt + NUMCONTS;
  1221. X
  1222. X  sscanf( String->Buffer, "%d", &Spacing );
  1223. X  spacing = Spacing;
  1224. X
  1225. X  if ( spacing <= 0 ) {
  1226. X    return;
  1227. X  }
  1228. X
  1229. X  First += SaveFirstCont;
  1230. X  Second = ContNum(Second);
  1231. X
  1232. X  ColorPatt += First;
  1233. X
  1234. X  if (First < Second) {
  1235. X
  1236. X    PattSize = Second - First + 1;
  1237. X  } else {
  1238. X
  1239. X    PattSize = First - Second + 1;
  1240. X    spacing = -spacing;
  1241. X  }
  1242. X
  1243. X  for ( i = 0; i < PattSize && ColorPatt >= CurPict->Pens && ColorPatt < Last;
  1244. X        i++ ) {
  1245. X
  1246. X    Pattern[ i ] = *ColorPatt;
  1247. X    ColorPatt += spacing;
  1248. X  }
  1249. X  PattSize = i;
  1250. X} /* CopyPattern */
  1251. X
  1252. X/*
  1253. X *  Set the pattern register to a list of consecutive pens
  1254. X */
  1255. XSetPenPattern(First,Second)
  1256. X  register int First, Second;
  1257. X{
  1258. X  register LONG i, spacing;
  1259. X
  1260. X  PattSize = Second - First;
  1261. X
  1262. X  if ( PattSize < 0 ) {
  1263. X    PattSize = - PattSize;
  1264. X    spacing = -1;
  1265. X  } else {
  1266. X    spacing =  1;
  1267. X  }
  1268. X  PattSize += 1;
  1269. X
  1270. X  for ( i = 0; i < PattSize; i++) {
  1271. X    Pattern[ i ] = First;
  1272. X    First += spacing;
  1273. X  }
  1274. X} /* SetPenPattern */
  1275. X
  1276. X/*
  1277. X *  Paste the pattern from the palette
  1278. X */
  1279. XPastePattern(First,Second)
  1280. X  register int First, Second;
  1281. X{
  1282. X  register int i, Spacing;
  1283. X  register UBYTE *ColorPatt = CurPict->Pens;
  1284. X  register struct StringInfo *String =
  1285. X              (struct StringInfo *) ModGadget->SpecialInfo;
  1286. X
  1287. X  LONG spacing;
  1288. X
  1289. X  register UBYTE *Last = ColorPatt + NUMCONTS;
  1290. X
  1291. X  if ( PattSize == 0 )
  1292. X    return;
  1293. X
  1294. X  sscanf( String->Buffer, "%d", &spacing );
  1295. X
  1296. X  Spacing = spacing;
  1297. X
  1298. X  if ( Spacing < 1 )
  1299. X    return;
  1300. X
  1301. X  First  += SaveFirstCont;
  1302. X  ColorPatt += First;
  1303. X  Second = ContNum(Second);
  1304. X
  1305. X  if (First < Second ) {
  1306. X
  1307. X    for ( i = 0; First <= Second && ColorPatt < Last;
  1308. X                 First += Spacing, i++ ) {
  1309. X
  1310. X      if ( i == PattSize )
  1311. X        i = 0;
  1312. X
  1313. X      *ColorPatt = Pattern[ i ];
  1314. X
  1315. X      ColorPatt += Spacing;
  1316. X    }
  1317. X  } else {
  1318. X
  1319. X    if (Second == 0) Second = 1;
  1320. X
  1321. X    for ( i = 0; Second < First && ColorPatt >= CurPict->Pens;
  1322. X                 First -= Spacing, i++ ) {
  1323. X
  1324. X      if ( i == PattSize )
  1325. X        i = 0;
  1326. X
  1327. X      *ColorPatt = Pattern[ i ];
  1328. X
  1329. X      ColorPatt -= Spacing;
  1330. X    }
  1331. X  }
  1332. X  DrawColorBox( ScaledFirst );
  1333. X  DrawColorBar();
  1334. X  ReDispPens();
  1335. X} /* PastePattern */
  1336. X
  1337. X/*
  1338. X *  Delete some contours from the contour list
  1339. X */
  1340. XDeleteContours(First,Second)
  1341. X  register int First, Second;
  1342. X{
  1343. X  register USHORT Temp;
  1344. X  register UBYTE *StartCP, *EndCP;
  1345. X  register int    Size,i;
  1346. X
  1347. X  struct StringInfo *String =
  1348. X         (struct StringInfo *) ModGadget->SpecialInfo;
  1349. X
  1350. X  LONG spacing;
  1351. X
  1352. X  sscanf( String->Buffer, "%d", &spacing );
  1353. X
  1354. X  if ( spacing < 1 )
  1355. X    return;
  1356. X
  1357. X  First  += SaveFirstCont;
  1358. X  Second = ContNum(Second);
  1359. X  Size = Second - First;
  1360. X
  1361. X  if (Size) {
  1362. X
  1363. X    if (Size < 0) {
  1364. X      Temp = First;
  1365. X      First = Second;
  1366. X      Second = Temp;
  1367. X
  1368. X      Size = -Size;
  1369. X      Temp = Size % spacing;
  1370. X      First += Temp;
  1371. X    }
  1372. X
  1373. X    StartCP = CurPict->Pens + First;
  1374. X
  1375. X    if (spacing == 1) {
  1376. X      EndCP = CurPict->Pens + Second;
  1377. X
  1378. X      Second = NUMCONTS - Second;
  1379. X
  1380. X      for (i = 0; i < Second; i++) {
  1381. X        *StartCP++ = *EndCP++;
  1382. X      }
  1383. X    } else {
  1384. X      EndCP   = StartCP + 1;
  1385. X
  1386. X      for ( ; First < Second; First += spacing ) {
  1387. X        for ( i = 0; i < spacing - 1; i++) {
  1388. X          *StartCP++ = *EndCP++;
  1389. X        }
  1390. X        EndCP++;
  1391. X      }
  1392. X    }
  1393. X
  1394. X    while ( StartCP < CurPict->Pens + NUMCONTS ) {
  1395. X      *StartCP++ = NORMALPEN;
  1396. X    }
  1397. X
  1398. X    DrawColorBox( ScaledFirst );
  1399. X    DrawColorBar();
  1400. X    ReDispPens();
  1401. X    ModAll();
  1402. X  }
  1403. X} /* DeleteContours */
  1404. X
  1405. X/*
  1406. X * ReDisplay all the contour potentiometer gadgets
  1407. X */
  1408. XModAll()
  1409. X{
  1410. X  register SHORT i;
  1411. X  register USHORT VertPot;
  1412. X  register USHORT Height;
  1413. X  register USHORT PrevHeight;
  1414. X
  1415. X  register struct Gadget *PropGad = (struct Gadget *) ContGadget[0];
  1416. X  register struct Picture *Pict = CurPict;
  1417. X
  1418. X  if (Ceiling > 0) {
  1419. X
  1420. X    if (FirstContour == 0) {
  1421. X
  1422. X      PrevHeight = Pict->Heights[ 0 ] + 1;
  1423. X
  1424. X    } else {
  1425. X
  1426. X      for (i = 0; i < FirstContour - 1; i++) {
  1427. X
  1428. X        Height = Pict->Heights[ i ];
  1429. X
  1430. X        if (Height < PrevHeight) {
  1431. X          PrevHeight = Height;
  1432. X        }
  1433. X      }
  1434. X    }
  1435. X
  1436. X    for (i = 0; i < DISPCONTS; i++) {
  1437. X
  1438. X      Height = CurPict->Heights[ i + FirstContour ];
  1439. X
  1440. X      SetPotPen( PropGad, PrevHeight, Height );
  1441. X
  1442. X      if (Height < PrevHeight)
  1443. X        PrevHeight = Height;
  1444. X
  1445. X      if ( Height < Ceiling) {
  1446. X
  1447. X        VertPot  = (Height<<16)/Ceiling;
  1448. X        if (VertPot > 0)
  1449. X          VertPot--;
  1450. X        VertPot ^= 0xffff;
  1451. X      } else
  1452. X
  1453. X        VertPot = (USHORT) 0;
  1454. X
  1455. X      NewModifyProp( PropGad, ContWind, NULL, FREEVERT|PROPBORDERLESS, 0L,
  1456. X               (long) VertPot, 0L, 0xffff/Ceiling, 1L);
  1457. X
  1458. X      PropGad = PropGad->NextGadget;
  1459. X    }
  1460. X  }
  1461. X} /* ModAll */
  1462. X
  1463. X/*
  1464. X * ReDisplay all the contour potentiometer gadgets
  1465. X */
  1466. XShowValid()
  1467. X{
  1468. X  register SHORT i;
  1469. X  register USHORT Height;
  1470. X  register USHORT PrevHeight;
  1471. X
  1472. X  register struct Gadget *PropGad = (struct Gadget *) ContGadget[0];
  1473. X  register struct Picture *Pict = CurPict;
  1474. X
  1475. X  if (Ceiling > 0) {
  1476. X
  1477. X    if (FirstContour == 0)
  1478. X      PrevHeight = Pict->Heights[ 0 ] + 1;
  1479. X    else
  1480. X      PrevHeight = Pict->Heights[ FirstContour - 1 ];
  1481. X
  1482. X    for (i = 0; i < DISPCONTS; i++) {
  1483. X
  1484. X      Height = CurPict->Heights[ i + FirstContour ];
  1485. X
  1486. X      if (SetPotPen( PropGad, PrevHeight, Height )) {
  1487. X        RefreshGList( PropGad, ContWind, NULL, 1);
  1488. X      }
  1489. X
  1490. X      if (Height < PrevHeight)
  1491. X        PrevHeight = Height;
  1492. X
  1493. X      PropGad = PropGad->NextGadget;
  1494. X    }
  1495. X  }
  1496. X} /* ShowValid */
  1497. X
  1498. XSetPotPen( PropGad, PrevHeight, Height )
  1499. X  register struct Gadget *PropGad;
  1500. X  register USHORT PrevHeight;
  1501. X  register USHORT Height;
  1502. X{
  1503. X  register int place,color;
  1504. X  register struct Image *Image;
  1505. X  extern int Num_vp_Colors;
  1506. X
  1507. X  Image = (struct Image *) PropGad->GadgetRender;
  1508. X
  1509. X  if (Height >= PrevHeight || Num_vp_Colors == 2)
  1510. X    color = SHADOWPEN;
  1511. X  else
  1512. X    color = HIGHLIGHTPEN;
  1513. X
  1514. X  if (Image->PlaneOnOff != color) {
  1515. X    place = RemoveGadget( ContWind, PropGad );
  1516. X    Image->PlaneOnOff = color;
  1517. X    AddGadget( ContWind, PropGad, place );
  1518. X    return(1);
  1519. X  }
  1520. X  return(0);
  1521. X}
  1522. X
  1523. X/*
  1524. X * ReDisplay all the pens gadgets
  1525. X */
  1526. XReDispPens()
  1527. X{
  1528. X  struct Gadget **Gadget = SelGadget;
  1529. X
  1530. X  register LONG Left = (*Gadget)->LeftEdge;
  1531. X  register LONG Top = (*Gadget)->TopEdge;
  1532. X  register LONG Bot = Top + (4 << YScale) - 1;
  1533. X
  1534. X  register LONG sixx  = 6 << XScale;
  1535. X  register LONG fourx = (4 << XScale) - 1;
  1536. X
  1537. X  register struct Image *Image;
  1538. X
  1539. X  LONG i;
  1540. X  struct RastPort *Rp = ContWind->RPort;
  1541. X  UBYTE *Pen = CurPict->Pens + FirstContour;
  1542. X
  1543. X  for (i = 0; i < DISPCONTS; i++) {
  1544. X
  1545. X    Image = (struct Image *) (*Gadget)->GadgetRender;
  1546. X
  1547. X    Image = Image->NextImage;
  1548. X
  1549. X    SetAPen( Rp, (long) (Image->PlaneOnOff = *Pen++) );
  1550. X
  1551. X    RectFill( Rp, Left, Top, Left + fourx, Bot);
  1552. X
  1553. X    Left += sixx;
  1554. X
  1555. X    Gadget++;
  1556. X  }
  1557. X
  1558. X  SetContTitle( 0 );
  1559. X}
  1560. X
  1561. Xstatic LONG WindowWidth;
  1562. Xstatic LONG WindowHeight;
  1563. X
  1564. Xstatic struct Border *BarBorder;
  1565. Xstatic struct Border *PenBorder;
  1566. Xstatic struct Border *ClnBorder;
  1567. X
  1568. X/*
  1569. X * Allocate all the gadgets and things for the contour window
  1570. X */
  1571. Xstruct Gadget *MakeContours()
  1572. X{
  1573. X  struct Gadget   *FirstGadget;
  1574. X  struct PropInfo *PropInfo;
  1575. X
  1576. X  register struct Gadget *NextGadget;
  1577. X  register struct IntuiText *Intui;
  1578. X
  1579. X  register ULONG i,x,y;
  1580. X  register ULONG c = 0;
  1581. X
  1582. X  int fourx = 4 << XScale;
  1583. X  int foury = 4 << YScale;
  1584. X  LONG sixx = 6 << XScale;
  1585. X  LONG sixy = 6 << YScale;
  1586. X
  1587. X  int Left,Top,Width;
  1588. X
  1589. X  char *str;
  1590. X
  1591. X  if ( XScale )
  1592. X    CurH = &Horiz_II;
  1593. X  else
  1594. X    CurH = &Horiz_I;
  1595. X
  1596. X  if ( YScale )
  1597. X    CurV = &Verticle_II;
  1598. X  else
  1599. X    CurV = &Verticle_I;
  1600. X
  1601. X  FirstContour = 0;
  1602. X  SaveFirstCont = 0;
  1603. X
  1604. X  PenBorder = ClnBorder = BarBorder = NULL;
  1605. X
  1606. X  BarBorder = ShadowBorder( BEVELEDUP, CurH->BarLeft - 4, CurV->BarTop - 2,
  1607. X                                       CurH->BarWidth,    CurV->BarHeight);
  1608. X  if (BarBorder == NULL) goto error;
  1609. X
  1610. X  PenBorder = ShadowBorder( BEVELEDUP, CurH->PenLeft - 4, CurV->PenTop - 3,
  1611. X                                       CurH->PenWidth,    CurV->PenHeight);
  1612. X  if (PenBorder == NULL) goto error;
  1613. X
  1614. X  Left = CurH->PenLeft + CurH->PenWidth + 2;
  1615. X
  1616. X  ClnBorder = ShadowBorder( BEVELEDUP, Left,      CurV->PenTop-3,
  1617. X                                       fourx + 5, CurV->PenHeight);
  1618. X  if (ClnBorder == NULL) goto error;
  1619. X
  1620. X  FirstGadget = NextGadget = MakePot( Left + 3, 30 << YScale,
  1621. X                                     fourx, 32 << YScale, CONTCEIL, 0);
  1622. X  if (NextGadget == NULL) goto error;
  1623. X
  1624. X  NextGadget->Activation = GADGIMMEDIATE | FOLLOWMOUSE | RELVERIFY;
  1625. X
  1626. X  Left = CurH->CmdLeft;
  1627. X  Top = CurV->CmdTop;
  1628. X
  1629. X  for (x = 0; x < 6; x++) {
  1630. X
  1631. X    switch (x) {
  1632. X      case 0: str = "Paint";  break;
  1633. X      case 1: str = "Set";    break;
  1634. X      case 2: str = "Smooth"; break;
  1635. X      case 3: str = "Cut";    break;
  1636. X      case 4: str = "Copy";   break;
  1637. X      case 5: str = "Paste";  break;
  1638. X    }
  1639. X
  1640. X    Width = 8 * strlen( str ) + 6;
  1641. X
  1642. X    NextGadget = NextGadget->NextGadget =
  1643. X      MakeBool( Left, Top, Width, 13, NORMALPEN, CONTCNTL+x, NULL);
  1644. X
  1645. X    if (NextGadget == NULL) goto error;
  1646. X
  1647. X    Intui = NextGadget->GadgetText = ShadowIntui( str, 4, 3);
  1648. X
  1649. X    if (Intui == NULL) goto error;
  1650. X
  1651. X    Left += 4 + Width;
  1652. X  }
  1653. X
  1654. X  /* Set up color bar below command gadgets */
  1655. X
  1656. X  BarBoxTop = CurV->BarTop;
  1657. X  BarTop = BarBot = BarBoxTop + 1;
  1658. X  BarBot += 4 << YScale;
  1659. X  BarBoxBot = BarBot + 1;
  1660. X
  1661. X  BarLeft = BarRight = CurH->BarLeft;
  1662. X  BarRight += 256 << XScale;
  1663. X  BarWidth = (DISPCONTS) << XScale;
  1664. X
  1665. X  Width = 8 * strlen("Last") + 4;
  1666. X
  1667. X  Top = CurV->PenTop;
  1668. X
  1669. X  NextGadget = NextGadget->NextGadget =
  1670. X    MakeBool( BarRight - Width + (2 << XScale), CurV->PenTop - 4, Width, 13,
  1671. X              NORMALPEN, CONTLAST, NULL);
  1672. X
  1673. X  if (NextGadget == NULL) goto error;
  1674. X
  1675. X  Intui = NextGadget->GadgetText = ShadowIntui( "Last", 3, 3);
  1676. X
  1677. X  if (Intui == NULL) goto error;
  1678. X
  1679. X  NextGadget->GadgetText = Intui;
  1680. X
  1681. X  i = CurH->PenLeft;
  1682. X
  1683. X  /* Make Set of Gadgets */
  1684. X
  1685. X  for (x = i, y = 0; y < DISPCONTS; x += sixx, y++) {
  1686. X
  1687. X    SelGadget[y] = NextGadget = NextGadget->NextGadget =
  1688. X      MakeBool(x, Top, fourx, foury, CurPict->Pens[ y + FirstContour ],
  1689. X               CONTSEL+y, GADGIMAGE );
  1690. X
  1691. X    if (NextGadget == NULL) goto error;
  1692. X  }
  1693. X
  1694. X  Top += sixy;
  1695. X
  1696. X  FirstGadget->TopEdge = Top;
  1697. X
  1698. X  Ceiling = CurPict->MaxIteration;
  1699. X
  1700. X  /*
  1701. X   * Allocate the potentiometer gadgets for contour window
  1702. X   */
  1703. X  for (x = i, y = 0; y < DISPCONTS; x += sixx, y++) {
  1704. X
  1705. X    ContGadget[y] = NextGadget = NextGadget->NextGadget =
  1706. X        MakePot(x, Top, 4 << XScale, 32 << YScale, CONTPOT+y, y);
  1707. X
  1708. X    if (NextGadget == NULL) goto error;
  1709. X
  1710. X    NextGadget->Activation = GADGIMMEDIATE | FOLLOWMOUSE | RELVERIFY;
  1711. X
  1712. X    c = CurPict->Heights[ y ];
  1713. X
  1714. X    if ( c < Ceiling )
  1715. X      c = (ULONG) ((((Ceiling - ( c + 1 ))<<16)/(Ceiling)) & 0xffff);
  1716. X    else
  1717. X      c = (ULONG) 0;
  1718. X
  1719. X    PropInfo = (struct PropInfo *) NextGadget->SpecialInfo;
  1720. X
  1721. X    PropInfo->VertPot = c;
  1722. X    PropInfo->VertBody = (USHORT) 0xffff/1024;
  1723. X  }
  1724. X
  1725. X  Top += 34 << YScale;
  1726. X
  1727. X  ModGadget = NextGadget = NextGadget->NextGadget =
  1728. X     MakeString( -28, -12 , 3, 0, "1" );
  1729. X
  1730. X  if ( NextGadget == NULL ) goto error;
  1731. X
  1732. X  NextGadget->Flags |= GRELBOTTOM | GRELRIGHT;
  1733. X  NextGadget->GadgetText = Intui = ShadowIntui( "Mod", 0, -11 );
  1734. X
  1735. X  if ( Intui == NULL ) goto error;
  1736. X
  1737. X  WindowHeight = CurV->PenTop + CurV->PenHeight + (2 << YScale);
  1738. X
  1739. X  if (XScale) {
  1740. X    WindowWidth = 534;
  1741. X  } else {
  1742. X    WindowWidth = 271;
  1743. X  }
  1744. X  return( FirstGadget );
  1745. X
  1746. Xerror:
  1747. X  FreeBorder( BarBorder );
  1748. X  FreeBorder( PenBorder );
  1749. X  FreeBorder( ClnBorder );
  1750. X  FreeGadgets( FirstGadget );
  1751. X  return( NULL );
  1752. X
  1753. X} /* MakeContours */
  1754. X
  1755. Xstatic struct Gadget *ContGadgets;
  1756. X
  1757. X/*
  1758. X * Open the Contour window
  1759. X */
  1760. Xint
  1761. XOpenContWind()
  1762. X{
  1763. X  register struct Gadget *gadgets;
  1764. X  register struct RastPort *Rp;
  1765. X
  1766. X  if (CurPict == NULL)
  1767. X    return;
  1768. X
  1769. X  if (ContWind == NULL) {
  1770. X
  1771. X    gadgets = MakeContours();
  1772. X
  1773. X    if (gadgets == NULL) {
  1774. X      DispErrMsg("Can't allocate contour gadget chain",0);
  1775. X      return(0);
  1776. X    }
  1777. X    ContWind = OpenMyWind(&NewCont, screen, NULL, WindowWidth,
  1778. X                          WindowHeight);
  1779. X
  1780. X    if (ContWind == NULL) {
  1781. X      FreeGadgets(gadgets);
  1782. X      return(0);
  1783. X    }
  1784. X    Rp = ContWind->RPort;
  1785. X
  1786. X    SetAPen( Rp, NORMALPEN );
  1787. X    RectFill( Rp, LEFTMARG, TOPMARG, WindowWidth, WindowHeight);
  1788. X
  1789. X    ContGadgets = gadgets;
  1790. X
  1791. X    BorderWindow( ContWind );
  1792. X
  1793. X    DrawBorder( Rp, BarBorder, 0L, 0L );
  1794. X    DrawBorder( Rp, PenBorder, 0L, 0L );
  1795. X    DrawBorder( Rp, ClnBorder, 0L, 0L );
  1796. X
  1797. X    FreeBorder( BarBorder );
  1798. X    FreeBorder( PenBorder );
  1799. X    FreeBorder( ClnBorder );
  1800. X
  1801. X    AddGList( ContWind, gadgets, -1L, -1L);
  1802. X
  1803. X    SetContTitle(0);
  1804. X
  1805. X    DrawColorBar();
  1806. X    DrawContBox( CurContour, HIGHLIGHTPEN );
  1807. X
  1808. X    RefreshGadgets( ContWind->FirstGadget, ContWind, NULL );
  1809. X    ModAll();
  1810. X  } else {
  1811. X
  1812. X    WindowToFront( ContWind );
  1813. X  }
  1814. X  ContOpen = 1;
  1815. X  return( 1 );
  1816. X} /* OpenContWind */
  1817. X
  1818. X/*
  1819. X * Close the Mand window
  1820. X */
  1821. XCloseContWind()
  1822. X{
  1823. X  if (ContWind != NULL) {
  1824. X
  1825. X    NewCont.LeftEdge = ContWind->LeftEdge;
  1826. X    NewCont.TopEdge = ContWind->TopEdge;
  1827. X
  1828. X    CloseMyWind(ContWind,ContGadgets);
  1829. X  }
  1830. X  ContWind = NULL;
  1831. X} /* ClosePalWind */
  1832. X
  1833. SHAR_EOF
  1834. echo "End of archive 1 (of 9)"
  1835. # if you want to concatenate archives, remove anything after this line
  1836. exit
  1837.